package com.sp.scmdb.utils;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sp.scmdb.entity.AlarmType;
import com.sp.scmdb.entity.Area;
import com.sp.scmdb.entity.AreaData;
import com.sp.scmdb.entity.Employee;
import com.sp.scmdb.entity.LabelReadingMachine;
import com.sp.scmdb.entity.Menu;
import com.sp.scmdb.entity.Path;
import com.sp.scmdb.entity.Reader_Alarm;
import com.sp.scmdb.entity.ShiftsDetails;

public class GroupList {

	public static Set<String> groupAreaOfReader(List<Area> areaList) {
		Set<String> readerSet = new HashSet<String>();
		for (Area area : areaList) {
			String readers = area.getReaders();
			String[] readerArr = readers.split(",");
			for (String reader : readerArr) {
				readerSet.add(reader);
			}
		}
		return readerSet;
	}

	public static Map<String, LabelReadingMachine> groupReaders(
			List<LabelReadingMachine> readerList) {
		Map<String, LabelReadingMachine> mapReaders = null;
		if (CollectionUtils.isNotEmpty(readerList)) {
			mapReaders = Maps.newHashMap();
			for (LabelReadingMachine labelReadingMachine : readerList) {
				mapReaders.put(String.valueOf(labelReadingMachine.getLrmID()),
						labelReadingMachine);
			}
		}
		return mapReaders;
	}

	public static Map<Integer, Employee> groupEmployee(
			List<Employee> employeeList) {
		Map<Integer, Employee> mapEmployee = null;
		if (CollectionUtils.isNotEmpty(employeeList)) {
			mapEmployee = Maps.newHashMap();
			for (Employee employee : employeeList) {
				mapEmployee.put(employee.getId(), employee);
			}
		}
		return mapEmployee;
	}

	public static Map<String, Menu> groupMenu(List<Menu> menuList) {
		Map<String, Menu> mapMenu = null;
		if (CollectionUtils.isNotEmpty(menuList)) {
			mapMenu = Maps.newHashMap();
			for (Menu menu : menuList) {
				mapMenu.put(String.valueOf(menu.getId()), menu);
			}
		}
		return mapMenu;
	}

	public static Map<String, Path> groupPath(List<Path> pathList) {
		Map<String, Path> mapPath = null;
		if (CollectionUtils.isNotEmpty(pathList)) {
			mapPath = Maps.newHashMap();
			for (Path path : pathList) {
				mapPath.put(String.valueOf(path.getId()), path);
			}
		}
		return mapPath;
	}
	public static Map<Integer, AlarmType> groupAlarmType(List<AlarmType> alarmTypeList) {
		Map<Integer, AlarmType> mapAlarmType= null;
		if (CollectionUtils.isNotEmpty(alarmTypeList)) {
			mapAlarmType = Maps.newHashMap();
			for (AlarmType alarmType : alarmTypeList) {
				mapAlarmType.put(alarmType.getId(), alarmType);
			}
		}
		return mapAlarmType;
	}

	public static Map<Integer, AreaData> groupAreaData(
			List<AreaData> areaDataList) {
		Map<Integer, AreaData> mapAreaData = Maps.newHashMap();
		if (CollectionUtils.isNotEmpty(areaDataList)) {
			for (AreaData areaData : areaDataList) {
				mapAreaData.put(areaData.getEmpID(), areaData);
			}
		}
		return mapAreaData;
	}

	public static Map<Integer, String> groupDayOfMonth(int maxDay) {
		Map<Integer, String> dayOfMonth = Maps.newTreeMap();
		for (int i = 1; i <= maxDay; i++) {
			dayOfMonth.put(i, String.valueOf(i));
		}
		return dayOfMonth;
	}

	public static Map<Integer, Area> groupArea(List<Area> areaList) {
		Map<Integer, Area> areaMaps = Maps.newHashMap();
		for (Area area : areaList) {
			areaMaps.put(area.getId(), area);
		}
		return areaMaps;
	}

	public static Map<Integer, List<ShiftsDetails>> groupShiftsDetails(
			List<ShiftsDetails> listShiftsDetails) {
		Map<Integer, List<ShiftsDetails>> shiftsDetailMap = Maps.newHashMap();
		for (ShiftsDetails shiftDetails : listShiftsDetails) {
			if (shiftsDetailMap.containsKey(shiftDetails.getIdShifts())) {
				shiftsDetailMap.get(shiftDetails.getIdShifts()).add(
						shiftDetails);
			} else {
				List<ShiftsDetails> tempShiftsDetails = Lists.newArrayList();
				tempShiftsDetails.add(shiftDetails);
				shiftsDetailMap.put(shiftDetails.getIdShifts(),
						tempShiftsDetails);
			}
		}
		return shiftsDetailMap;
	}
	public static Map<Integer, Reader_Alarm> groupReaderAlarm(List<Reader_Alarm> readerAlarmList) {
		Map<Integer, Reader_Alarm> mapReaderAlarm= null;
		if (CollectionUtils.isNotEmpty(readerAlarmList)) {
			mapReaderAlarm = Maps.newHashMap();
			for (Reader_Alarm ra : readerAlarmList) {
				mapReaderAlarm.put(ra.getLrmID(), ra);
			}
		}
		return mapReaderAlarm;
	}
}
